
# Define The GIM path (Relative here)
GDIR=../../../..

CC=gcc
CXX=g++
EXTRADEFS=-DLINUX_OS -DOVERRIDE_DEVICE_INIT_CHECK \
	-DGIMI_NO_DATATYPE_INCLUDES \
	-DGIMI_CLIENT_API=10403
INCLUDES=-I. -I$(GDIR)/utils -I$(GDIR)/nif -I$(GDIR)/bitestream \
	-I$(GDIR)/GIMI -I$(GDIR)/ASRobo/client -I$(GDIR)/ASRobo $(OCCU_INCLUDE) \
	-I$(SMDIR) -I$(GDIR)/glutImageGUI -I$(GDIR)/glutgui
	
CFLAGS=-O2 -g0 -Wall `xml2-config --cflags` $(INCLUDES) $(CE) $(EXTRADEFS)
CPPFLAGS=-O2 -g0 -Wall `xml2-config --cflags` $(INCLUDES) $(CE) $(EXTRADEFS)
LD=g++
LDFLAGS=
LIBS=-lrt -lpthread `xml2-config --libs` -lGL -lGLU -lglut
	

# Get External Sources lists
include $(GDIR)/GIMI/Makefile.gimi
include $(GDIR)/ASRobo/client/Makefile.asroboclient

GIMDIR=$(GDIR)
include $(GDIR)/grid/Makefile.occu 

SMDIR = $(GDIR)/LnMlib/src/scanmatch
CPPSM = $(SMDIR)/CAHistogramECorrelationScanMatch.cpp

CPPIMAGEGUI = $(GDIR)/glutImageGUI/glutImageGUI.cpp
RGBDATA = $(GDIR)/glutgui/RGBImage.cpp

# Combine All Required Sources 
SRCSC := $(CGIMI) $(CASROBOCLIENT)
SRCSCPP := $(CPPGIMI) $(CPPASROBOCLIENT) $(CPPSM) $(OCCU_SRC_CPP) $(CPPIMAGEGUI) $(RGBDATA)\
	main.cpp J2B2OccuSLAM.cpp
VPATH=

# Construct final lists of CPP and C objects
OBJSC := $(SRCSC:.c=.o)
OBJSCPP := $(SRCSCPP:.cpp=.opp)

# Define COMPILE and LINK commands
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)


# Define PHONY targets
.PHONY: all clean

# Define ALL rule
#all:	occuslam libj2b2GIMICtrl.a dist
all:	occuslam

occuslam: $(OBJSC) $(OBJSCPP)
			$(LINK) -o $@ $(OBJSC) $(OBJSCPP)

# Define normal targets...
j2b2GIMICtrlTest: main.opp libj2b2GIMICtrl.a
	$(LINK) -L. -o $@ main.opp -lj2b2GIMICtrl

# Library target
libj2b2GIMICtrl.a: $(OBJSC) $(OBJSCPP)
	ar rv $@ $?
	ranlib $@
	@echo "Library $@ created OK"

DIST_DIR = mapper

HEADERS = $(GDIR)/include


# Distribution target
.PHONY: dist
dist:
	mkdir $(DIST_DIR); mkdir $(DIST_DIR)/inc; cp -r $(HEADERS) $(DIST_DIR);\
	cp $(SRCSC) $(SRCSCPP) $(DIST_DIR); cp Makefile.dist $(DIST_DIR)/Makefile;

# dist:	libj2b2GIMICtrl.a 
# 	mkdir -p dist/lib/linux
# 	cp -r ${GDIR}/utils \
#         ${GDIR}/nif \
#         ${GDIR}/bitestream \
#         ${GDIR}/GIMI \
#         ${GDIR}/ASRobo \
#         ${GDIR}/imageclient \
#         ${GDIR}/tcpHub \
# 	j2b2GIMICtrl.hpp dist
# 	cp libj2b2GIMICtrl.a dist/lib/linux
# 	find ./dist -type f -a ! -iname "*.hpp" -a ! -iname "*.h" -a \
# 	! -name cleanup -a ! -name libj2b2GIMICtrl.a -exec rm {} \;
# 	rmdir `find ./dist -type d -name CVS`



# Define CLEAN rule
clean:
	rm -f $(OBJSC) $(OBJSCPP)	
	find -name "*~" -exec rm {} \; 
	find -name "*.dpp" -exec rm {} \;
	find -name "*.d" -exec rm {} \;
#rm -f libj2b2GIMICtrl.a
#rm -rf ./dist

### Compile rules
# Compile rule for all .o (.c) file
%.o:	%.c
	$(COMPILEC) -o $@ $<

# Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
	$(COMPILECPP) -o $@ $<